﻿ <% layout('adminlayout.html') -%>


<div ng-app="app" ng-controller="appController">
    <div>
        <ul class="nav nav-tabs">
            <li role="presentation" ng-class="{'active':flag=='1'}" ng-click="flag=1"><a href="#">已读留言</a></li>
            <li role="presentation" ng-class="{'active':flag=='0'}" ng-click="flag=0"><a href="#">未读留言</a></li>
        </ul>
    </div>
    
    <div class="alert alert-success" role="alert" style="margin-top:30px;">
        快速检索，输入关键字：<input type="text" ng-model="query" style="height:30px; border-radius:3px;border:1px solid #ddd;" />
        <button class="btn btn-success" ng-click="read()" ng-show="flag==0">标示成已读</button>
        <button class="btn btn-danger" ng-click="unread()" ng-show="flag==1">标示成未读</button>
    </div>


    <div>
        <table class="table">
            <tr>
                <th>选项</th>
                <th>称谓</th>
                <th>电话</th>                
                <th>微信号</th>
                <th>留言内容</th>
                <th>留言时间</th>                
            </tr>
            <tr ng-repeat="o in list |filter:{'flag':flag} | filter:query | orderBy:'createDate':true">
                <td><input type="checkbox" ng-model="o.select" /></td>
                <td>{{o.name}}</td>
                <td>{{o.telphone}}</td>
                <td>{{o.weixin}}</td>
                <td>{{o.leaveMsg}}</td>
                <td>{{o.createDate | date: 'yyyy-MM-dd HH:mm:ss '}}</td>
            </tr>
            <tr><td colspan="10" style="color:#f00;">记录数：{{(list |filter:{'flag':flag} | filter:query ).length}}</td></tr>
        </table>
    </div>

    <div class="loading">
        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-body">
                        <div style="text-align:center;"><img src="../images/load.gif" /></div>
                        <div style="text-align:center;"><h1 style="color:#ff6a00;font-size:16px;">正在加载,请稍后......</h1></div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.modal -->
    </div>
</div>



<script>
    var app = angular.module("app", []);   
    app.controller('appController', function ($scope, $http) {
        $scope.flag = '0';
        $scope.loadData = function () {
            showLoading();
            var Jsondata = {};
            $http({
                url: '/admin/Getmessages',
                method: 'POST',
                data: Jsondata
            }).success(function (response) {
                $scope.list = response;
                closeLoading();
            }).error(function () {
                //alert("error");
                closeLoading();
            })
        }
        $scope.loadData();

        
        $scope.read = function () {
            $scope.updateObj = [];
            angular.forEach($scope.list, function (o) {
                if (o.select && o.flag == "0") {
                    o.flag = "1";
                    o.select = false;
                    $scope.updateObj.push(o);
                }
            })
            $scope.update();
        }

        $scope.unread = function () {
            $scope.updateObj = [];
            angular.forEach($scope.list, function (o) {
                if (o.select&&o.flag=="1") {
                    o.flag = "0";
                    o.select = false;
                    $scope.updateObj.push(o);
                }
            })
            $scope.update();
        }

        $scope.update = function () {
            var Jsondata = {};
            Jsondata.list = $scope.updateObj;
            //alert(JSON.stringify(Jsondata));
            $http({
                url: '/admin/updateMsgFlag',
                method: 'POST',
                data: Jsondata
            }).success(function (response) {
                //$scope.list = response;
                //closeLoading();
            }).error(function () {
                //alert("error");/
            })
        }
    });

</script>

